package cn.edu.nju.software.action.transaction;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import cn.edu.nju.software.bean.show.BookItemInOrder;
import cn.edu.nju.software.util.Constants;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class RemoveCartBookAction extends ActionSupport implements SessionAware {

	private int id;
	private Map<String, Object> session;
	
	public void setId(int id) {
		this.id = id;
	}

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
	
	@Override
	public String execute() throws Exception {
		@SuppressWarnings("unchecked")
		List<BookItemInOrder> cart = (List<BookItemInOrder>) session.get(Constants.SESSION_CART);
		for (BookItemInOrder item : cart) {
			if (item.getBook().getBookID() == id) {
				cart.remove(item);
				break;
			}
		}
		return SUCCESS;
	}
}
